package com.wwz.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.wwz.entity.Permission;
import com.wwz.entity.Result;
import com.wwz.model.PermissionModel;
import com.wwz.query.PermissionQuery;
import com.wwz.service.IPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("permission")
@Api(tags = "权限控制器")
public class PermissionController{

    @Resource
    private IPermissionService permissionService;

    @GetMapping("toPage")
    @ApiOperation("权限列表")
    public Result toPage(PermissionQuery query){
        IPage<Permission> iPage = permissionService.toPage(query);
        return Result.ok(iPage);
    }

    @PostMapping("addOrUpData")
    @ApiOperation("添加或修改")
    public Result addOrUpData(@RequestBody PermissionModel permissionModel){
        permissionService.addOrUpData(permissionModel);
        return Result.ok("操作成功");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除权限")
    public Result deleteById(@PathVariable String id){
        permissionService.deleteById(id);
        return Result.ok("删除成功");
    }

}

